package com.endoc.designpattern.chain;

import com.endoc.designpattern.strategy.Discount;

/**
 * 优惠责任链抽象类
 */
public abstract class AbstractChainDiscount implements Discount {

    protected AbstractChainDiscount nextAbstractChainDiscount;//下一个优惠节点

    public AbstractChainDiscount(AbstractChainDiscount nextAbstractChainDiscount) {
        this.nextAbstractChainDiscount = nextAbstractChainDiscount;
    }

    @Override
    public int calculate(int money) {
        //子类重写,实现自己的优惠逻辑后
        /*
        * 子类逻辑.....
        * */

        //如果有下一个节点,那么把逻辑交由下一个处理
        if(nextAbstractChainDiscount!=null){
            //此处直接传入money是可以对money计算后重新赋值
          return   nextAbstractChainDiscount.calculate(money);
        }
        return money;
    }

}
